#include "ColorBarOptionsWrapper.h"

#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>

#include <odv/odvCore/ColorBarOptions.h>

namespace py = pybind11;

void bind_ColorBarOptions(py::module_ &m) {
  // 绑定枚举 ColorBarPreset
  py::enum_<odv::ColorBarPreset>(m, "ColorBarPreset")
      .value("Blank", odv::ColorBarPreset::Blank)
      .value("Grayscale", odv::ColorBarPreset::Grayscale)
      .value("Jet", odv::ColorBarPreset::Jet)
      .value("Hot", odv::ColorBarPreset::Hot)
      .value("Code", odv::ColorBarPreset::Code)
      .value("Night", odv::ColorBarPreset::Night)
      .value("Candy", odv::ColorBarPreset::Candy)
      .value("Geography", odv::ColorBarPreset::Geography)
      .value("Ion", odv::ColorBarPreset::Ion)
      .value("Thermal", odv::ColorBarPreset::Thermal)
      .value("Polar", odv::ColorBarPreset::Polar)
      .value("Spectrum", odv::ColorBarPreset::Spectrum)
      .value("Hues", odv::ColorBarPreset::Hues)
      .value("Rainbow", odv::ColorBarPreset::Rainbow)
      .value("Heatmap", odv::ColorBarPreset::Heatmap)
      .value("Coolwarm", odv::ColorBarPreset::Coolwarm)
      .value("Blues", odv::ColorBarPreset::Blues)
      .value("Greens", odv::ColorBarPreset::Greens)
      .value("Purples", odv::ColorBarPreset::Purples)
      .value("YlGnBu", odv::ColorBarPreset::YlGnBu)
      .value("RdYlGn", odv::ColorBarPreset::RdYlGn)
      .export_values();

  // 绑定 Color 类
  py::class_<odv::Color>(m, "Color")
      .def(py::init<float, float, float, float>(), py::arg("r") = 0,
           py::arg("g") = 0, py::arg("b") = 0, py::arg("a") = 1)
      .def(py::init<const std::array<float, 4> &>())
      .def(py::init<std::initializer_list<float>>())
      .def(py::init<const odv::Color &>())
      .def("r", py::overload_cast<>(&odv::Color::r))
      .def("g", py::overload_cast<>(&odv::Color::g))
      .def("b", py::overload_cast<>(&odv::Color::b))
      .def("a", py::overload_cast<>(&odv::Color::a))
      .def("r", py::overload_cast<>(&odv::Color::r, py::const_))
      .def("g", py::overload_cast<>(&odv::Color::g, py::const_))
      .def("b", py::overload_cast<>(&odv::Color::b, py::const_))
      .def("a", py::overload_cast<>(&odv::Color::a, py::const_))
      .def(py::self == py::self)
      .def(py::self != py::self)
      .def("__repr__", [](const odv::Color &c) {
        return "Color(r=" + std::to_string(c.r()) +
               ", g=" + std::to_string(c.g()) + ", b=" + std::to_string(c.b()) +
               ", a=" + std::to_string(c.a()) + ")";
      });

  // 绑定 ColorBarOptions 结构体
  py::class_<odv::ColorBarOptions, std::shared_ptr<odv::ColorBarOptions>>(
      m, "ColorBarOptions")
      .def(py::init<>())
      .def(py::init<std::map<float, odv::Color>, float, float>(),
           py::arg("colors"), py::arg("minValue"), py::arg("maxValue"))
      .def(py::init<const odv::ColorBarOptions &>())
      .def_readwrite("minValue", &odv::ColorBarOptions::minValue)
      .def_readwrite("maxValue", &odv::ColorBarOptions::maxValue)
      .def_readwrite("colors", &odv::ColorBarOptions::colors)
      .def_readwrite("samples", &odv::ColorBarOptions::samples)
      .def_readwrite("showColorBar", &odv::ColorBarOptions::showColorBar)
      .def_readwrite("title", &odv::ColorBarOptions::title)
      .def_readwrite("font", &odv::ColorBarOptions::font)
      .def_readwrite("tickCount", &odv::ColorBarOptions::tickCount)
      .def_readwrite("showTicks", &odv::ColorBarOptions::showTicks)
      .def("__repr__", [](const odv::ColorBarOptions &o) {
        return "ColorBarOptions(min=" + std::to_string(o.minValue) +
               ", max=" + std::to_string(o.maxValue) +
               ", colors.size=" + std::to_string(o.colors.size()) + ")";
      });
}
